package com.kkb.kkbadmin.controller;


import com.github.pagehelper.PageInfo;
import com.kkb.kkbadmin.domain.dto.UserDto;
import com.kkb.kkbadmin.domain.vo.FameBGListVO;
import com.kkb.kkbadmin.service.UserService;
import com.kkb.kkbcommon.api.CommonPage;
import com.kkb.kkbcommon.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户表 前端控制器
 *
 * @author 赵裕源
 * @since 2021-08-15
 */
@RestController
@Api(tags = "用户管理", value = "名人堂后台管理")
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据roleId角色编号返回用户列表List
     *
     * @param roleId    角色编号 1: 学员  2: 导师
     * @param condition 包含用户名的搜索条件
     * @param pageNum   页码
     * @param pageSize  每页显示数量
     * @return 分页结果
     */
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "用户角色id", dataType = "long"),
            @ApiImplicitParam(name = "condition", value = "用户筛选条件", dataType = "User"),
            @ApiImplicitParam(name = "pageNum", value = "当前页数", defaultValue = "1", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", defaultValue = "5", dataType = "int")
    })
    @PostMapping("/page/{roleId}")
    public CommonResult<CommonPage<FameBGListVO>> listPage(@PathVariable Long roleId,
                                                           @Validated @RequestBody UserDto condition,
                                                           @RequestParam(defaultValue = "1") Integer pageNum,
                                                           @RequestParam(defaultValue = "5") Integer pageSize) {
        PageInfo<FameBGListVO> page = userService.findPage(roleId, condition, pageNum, pageSize);
        CommonPage<FameBGListVO> commonPage = CommonPage.restPage(page.getList());
        return CommonResult.success(commonPage);
    }
}

